Application programming interfaces for interaction
with the Eclipse Java User Interface text support.
Linked Position Infrastructure
package org.eclipse.jdt.internal.ui.text.link
The Linked Position Infrastructure lets one set up a mode in an editor
in which regions in a document (or several documents) are linked,
i.e. editions
of one linked position will be reflected in the others.
Classes
PositionGroup
: a set of linked positions. Add
positions to a group using the addPosition
methods, which
also allow to specify an iteration order, and completion proposals to
be shown when a position is hit.
LinkedEnvironment
: umbrellas several PositionGroup
s,
e.g. in a template that has several groups of linked positions. Handles
the forwarding of updates received via an IDocumentListener. Add PositionGroup
s
to
an environment using the addGroup
method. A linked
environment can be obtained using one of the provided static methods.
LinkedUIControl
: The UI for linked mode (for one
environment, to be precise). Monitors key etc. activity, monitors exit
conditions, creates a painter etc.
Properties:
- cycling mode (whether to jump to the first position
after the last): either of
CYCLE_ALWAYS
, CYCLE_NEVER
and CYCLE_WHEN_NO_PARENT
(default).
- exit position: where to jump upon leaving the linked
mode (e.g. using Enter, or Tab from the last position when not
cycling). Set
isTabStop
to true
if tabbing
should stop over when cycling.
.
Example
IDocument doc1, doc2;
ITextViewer viewer1, viewer2;
/* create groups - this step is independent of the linked mode */
PositionGroup group1= new PositionGroup();
group1.addPosition(doc1, 3,4);
group1.addPosition(doc1, 7,8);
PositionGroup group2= newPositionGroup();
group2.addPosition(doc1, 15, 25);
group2.addPosition(doc2, 0, 10);
/* set up linked mode */
LinkedEnvironment env= LinkedEnvironment.createEnvironment(new IDocument[] {doc1, doc2});
env.addGroup(group1);
env.addGroup(group2);
/* create UI */
LinkedUIControl ui= new LinkedUIControl(env, new ITextViewer[] { viewer1, viewer2 });
ui.enter();
Todo
Items with an asterix (*) are must haves before merging this into HEAD.
- handle closing behaviour on shell deactivation (make sure we
don't exit if a code completion window gets focus).
- This can be handles as in the old LinkedPositionUI.
- handle lazy computation of per-group proposals using a
IContentAssistProcessor
(see PositionGroup) .
- handle interaction with the standard context information popup
(since it is a verify key listener, it does not get informed about
caret changes if we filter them away in front of it. Need some other
information flow).
- Steps:
- Create a new class like the one below:
class Clazz {
int kompute(int param) {
return kompute<CARET>;
}
}
- Invoke content assist with "automatically insert single
proposals" turned on.
- Repeat recursively placing new invocations of kompute as the parameter of the
function.
- Note: as we step down recursively, the context info box
comes along and displays the parameter info.
- Note: the linked mode follows into the recursion
- Finally enter a different parameter (e.g. 2) and press TAB to
leave one level
- Note: one link level is left, the surrounding entry is
underlined
- Note: the context info stays with the innermost parameter.
- Press TAB repeatedly until behind the last closing
parenthesis - all linked modes have been left
- Note: the context info is still with the innermost
parameter.
- Press ESC repeatedly to see the context info jump back from
level to level.